package link.xieyu.config;

import link.xieyu.entity.Access;
import link.xieyu.entity.AliyunDomainAnalysis;

import java.io.IOException;
import java.util.Properties;

/**
 * @author xieyu
 */
public class ReadConfig {
    public ReadConfig() {
        Properties properties = new Properties();
        try {
            properties.load(getClass()
                                    .getClassLoader()
                                    .getResourceAsStream("aliyun.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        this.access = new Access(properties.getProperty("access-key.id"),
                                 properties.getProperty("access-key.secret"));

        aliyunDomainAnalysis =
                new AliyunDomainAnalysis(properties.getProperty("domain.rr"),
                                         properties.getProperty("domain.type"),
                                         properties.getProperty("domain.domain-name"));

    }

    /**
     *
     * @param propertiesName 配置名字(需要在classPath内)
     */
    public ReadConfig(String propertiesName){
        Properties properties = new Properties();
        try {
            properties.load(getClass()
                                    .getClassLoader()
                                    .getResourceAsStream(propertiesName));
        } catch (IOException e) {
            e.printStackTrace();
        }
        this.access = new Access(properties.getProperty("access-key.id"),
                                 properties.getProperty("access-key.secret"));

        aliyunDomainAnalysis =
                new AliyunDomainAnalysis(properties.getProperty("domain.rr"),
                                         properties.getProperty("domain.type"),
                                         properties.getProperty("domain.domain-name"));
    }

    private final Access access;
    private final AliyunDomainAnalysis aliyunDomainAnalysis;

    public Access getAccess() {
        return access;
    }

    public AliyunDomainAnalysis getAliyunDomainAnalysis() {
        return aliyunDomainAnalysis;
    }
}
